<?php namespace App\Http\Middleware;

use Closure;
use Illuminate\HttpResponse;
use Illuminate\Http\Request;
use Session;
class WebAuthMiddleware {

	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */
	public function handle($request, Closure $next)
	{
        if (strpos($request->path(),'login') === false && !Session::get('adminName')) {
//            return redirect("/console/login");
            if (Request::ajax()) {
//                return Response::json(["state"=>0,"msg"=>"请登录"]);
                return "请登录";
            } else {
                echo "<script language=\"javascript\">";
                echo "location.replace(\"/console/login\");";
                echo "</script>";
            }

        } else {
            return $next($request);
        }
	}

}
